<template>
  <div class="card-warp" :style="{background:pBgcolor}" @click="clickbtn">
    <template v-if="isCard">
      <div class="icon" :style="[bgStyle, isRadius]">
        <slot name="icon" />
      </div>
      <div class="text">
        <div
          class="top"
          :class="isHighlight == 'top' ? 'highlight' : ''"
        >
          <slot name="top" />
        </div>
        <div
          class="bottom"
          :class="isHighlight == 'bottom' ? 'highlight' : ''"
        >
          <slot name="bottom" />
        </div>
      </div>
    </template>
    <template v-else>
      <slot name="panle" />
    </template>
  </div>
</template>

<script>
export default {
  props: {
    isCard: {
      type: Boolean,
      default: true
    },
    isLeftBorder: {
      type: Boolean,
      default: false
    },
    isBorder: {
      type: Boolean,
      default: false
    },
    isShadow: {
      type: Boolean,
      default: false
    },
    isGradient: {
      type: Boolean,
      default: false
    },
    isHighlight: {
      type: String,
      default: ''
    },
    // 父级容器背景色
    pBgcolor: {
      type: String,
      default: '#f3f5f8'
    },
    // icon背景色
    bgColor: {
      type: String,
      default: ''
    },
    // icon边框样式
    borderColor: {
      type: String,
      default: ''
    },
    // icon阴影样式
    shadowColor: {
      type: String,
      default: ''
    },
    // icon圆角样式
    radius: {
      type: String,
      default: '0'
    },
    gradColor: {
      type: Array,
      default: () => ['#fca51c', '#fdc811']
    }
  },

  computed: {
    bgStyle() {
      let style
      // 有左侧边框
      const bgcolor = this.bgColor !== '' ? this.bgColor : '#fff'
      if (this.isLeftBorder) {
        style = {
          background: bgcolor,
          borderLeft: `3px solid ${this.borderColor}`
        }
      } else if (this.isGradient) {
        // 图片渐变
        style = {
          backgroundImage: `linear-gradient(-40deg, ${this.gradColor[0]} 0%, ${this.gradColor[1]} 100%), linear-gradient(	#fba74c, 	#fba74c)`,
          backgroundBlendMode: `normal, normal`
        }
      } else if (this.isBorder) {
        // 有边框
        style = {
          background: bgcolor,
          border: `4px solid ${this.borderColor}`
        }
      } else if (this.isShadow) {
        // 有阴影
        style = {
          background: bgcolor,
          boxShadow: `0px 0px 16px 0px ${this.shadowColor}`
        }
      } else {
        style = {
          background: bgcolor
        }
      }
      return style
    },
    isRadius() {
      let style
      if (this.radius !== '') {
        style = {
          borderRadius: this.radius
        }
      }
      return style
    }
  },
  methods: {
    clickbtn() {
      this.$emit('clickbtn')
    }
  }
}
</script>

<style lang="scss" scoped>
.card-warp {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
	border-radius: 2px;
  padding: 25px 20px;
  .icon {
    width: 56px;
    height: 56px;
    text-align: center;
    line-height: 55px;
    margin-right: 15px;
    i {
      font-size: 24px;
      color: #fff;
    }
  }
  .text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    .highlight {
      span {
        line-height: 16px;
        color: #272c29;
        font-weight: bold;
        margin-top: 14px;
        display: inline-block;
        i{
          font-size: 20px;
        }
      }
    }
  }
}
</style>
